﻿using DomainService.IService.Sys;
using DomainService.Service.Sys;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model.BusinessModel.InPut;
using Model.BusinessModel.OutPut;
using Model.BusinessModel.OutPut.sys;
using Model.DomainModel.Sys;
using Utility;
using Utility.Enum;

namespace OverallAuth_WebApi.Controllers.Sys
{
    /// <summary>
    /// 系统api
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    [ApiExplorerSettings(GroupName = nameof(ModeuleGroupEnum.SysSystem))]
    public class SysSystemController : BaseController
    {
        #region 构造实列化

        /// <summary>
        /// 系统服务
        /// </summary>
        public ISysSystemService _sysSystemService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sysSystemService"></param>
        public SysSystemController(ISysSystemService sysSystemService)
        {
            _sysSystemService = sysSystemService;
        }

        #endregion

        #region 接口

        /// <summary>
        ///  获取项目系统数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<SysSystemOutPut> GetSystemList()
        {
            ReceiveStatus<SysSystemOutPut> receiveStatus = new();
            var list = _sysSystemService.GetSystemList(GetLoginUserMsg().CorporationKey);
            receiveStatus.data = list;
            return receiveStatus;

        }

        /// <summary>
        /// 获取公司所有系统,select结构
        /// </summary>
        /// <param name="corporationKey">公司key</param>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<SelectOutPut> GetAllByCorporationKey(string? corporationKey)
        {
            return _sysSystemService.GetSystemByCorporationKey(corporationKey ?? string.Empty);
        }

        /// <summary>
        /// 新增系统
        /// </summary>
        /// <param name="sysSystem">系统数据</param>
        [HttpPost]
        public ReceiveStatus Insert(SysSystem sysSystem)
        {
            sysSystem.CreateTime = DateTime.Now;
            sysSystem.CreateUser = GetLoginUserMsg().UserId;
            return _sysSystemService.Insert(sysSystem);
        }

        /// <summary>
        /// 修改系统
        /// </summary>
        /// <param name="sysSystem">系统数据</param>
        [HttpPost]
        public ReceiveStatus Update(SysSystem sysSystem)
        {
            return _sysSystemService.Update(sysSystem);
        }

        /// <summary>
        /// 设置系统是否启用
        /// </summary>
        /// <param name="updateIsOpenInPut">修改模型</param>
        [HttpPost]
        public ReceiveStatus SetSystemIsOpen(UpdateIsOpenInPut updateIsOpenInPut)
        {
            return _sysSystemService.SetSystemIsOpen(updateIsOpenInPut);
        }

        #endregion
    }
}
